
// C++ STL
#include <memory>
#include <string>
using namespace std;
// C API
#include <stdio.h>

#ifndef APPENDFILE_HPP
#define APPENDFILE_HPP

namespace tulun
{
    class AppendFile // fopen write close
    {
    private:
        static const size_t FILE_BUFF_SIZE = 1024 * 1024 * 10;
        std::unique_ptr<char[]> buffer_; // new char[10M];
        FILE *fp_;
        size_t writeBytes_;
        size_t write(const char *msg, const size_t len);

    public:
        AppendFile(const std::string &filename);
        ~AppendFile();

        void append(const std::string &msg);
        void append(const char *msg, const size_t len);
        void flush();
        size_t getWriteBytes() const;
    };
} // namespace tulun

#endif